import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    UserInfo: JSON.parse(sessionStorage.getItem("UserInfo")) || {},
    IsCollapse: false,
    RouterDt: JSON.parse(sessionStorage.getItem("RouterDt")) || []
  },
  mutations: {
    SetIsCollapse (state) {
      state.IsCollapse = !state.IsCollapse;
    },
    //修改用户信息
    SetUserInfo (state, payload) {
      state.UserInfo = payload
      sessionStorage.setItem("UserInfo", JSON.stringify(payload));
    },
    //修改头像
    SetUserImg (state, payload) {
      state.UserInfo.ImageData = payload;
      sessionStorage.setItem("UserInfo", JSON.stringify(state.UserInfo));
    },
    //修改路由
    SetRouterDt (state, payload) {
      //state.RouterDt = filterAsyncRouter(payload);
      state.RouterDt = payload;
      sessionStorage.setItem("RouterDt", JSON.stringify(payload));
    }
  },
  actions: {
    SetUserInfo (context, payload) {
      context.commit('SetUserInfo', payload)
    },
    SetUserImg (context, payload) {
      context.commit('SetUserImg', payload)
    },
    SetRouterDt (context, payload) {
      context.commit('SetRouterDt', payload)
    }
  },
  modules: {
  }
})

